//
//  SignatureView.m
//  CarLife
//
//  Created by yu on 2018/2/8.
//  Copyright © 2018年 jpas. All rights reserved.
//

#import "SignatureView.h"

@interface SignatureView ()

@property (nonatomic, strong) UIButton *cancelBtn;

@property (nonatomic, strong) UIButton *confirmBtn;

@property (nonatomic, strong) UIButton *resignBtn;

@property (nonatomic, strong) UILabel *tipLabel;

@end

@implementation SignatureView

- (instancetype)init
{
    if (self = [super init]) {
        
        UIView *bgView = [[UIView alloc] init];
        bgView.backgroundColor = kBaseColor;
        [self addSubview:bgView];
        
        self.cancelBtn = [[UIButton alloc] init];
//        [self.cancelBtn setBackgroundColor:[UIColor blueColor]];
        [self.cancelBtn setTitle:@"取消" forState:UIControlStateNormal];
        [self.cancelBtn addTarget:self action:@selector(cancelAction) forControlEvents:UIControlEventTouchUpInside];
        [bgView addSubview:self.cancelBtn];
        
        self.confirmBtn = [[UIButton alloc] init];
//        [self.confirmBtn setBackgroundColor:[UIColor blueColor]];
        [self.confirmBtn setTitle:@"确定" forState:UIControlStateNormal];
        [self.confirmBtn addTarget:self action:@selector(confirmAction) forControlEvents:UIControlEventTouchUpInside];
        [bgView addSubview:self.confirmBtn];
        
        self.signView = [[BJTSignView alloc] init];
//        self.signView.backgroundColor = [UIColor greenColor];
        self.signView.layer.borderColor = [UIColor lightGrayColor].CGColor;
        self.signView.layer.borderWidth = 1;
        [self addSubview:self.signView];
        
        self.resignBtn = [[UIButton alloc] init];
        [self.resignBtn setTitle:@"重签" forState:UIControlStateNormal];
        [self.resignBtn addTarget:self action:@selector(resignAction) forControlEvents:UIControlEventTouchUpInside];
        [bgView addSubview:self.resignBtn];
        
        
        self.tipLabel = [[UILabel alloc] init];
        self.tipLabel.text = @"注意：请保持字迹工整；";
        self.tipLabel.font = [UIFont systemFontOfSize:10];
//        self.tipLabel.backgroundColor = [UIColor blueColor];
        self.tipLabel.textColor = [UIColor redColor];
        [self addSubview:self.tipLabel];
        
        CGFloat margin10 = 10.0;CGFloat margin15 = 15.0;
        
        {
            bgView.sd_layout
            .leftEqualToView(self)
            .rightEqualToView(self)
            .topEqualToView(self)
            .heightIs(40);
            
            self.cancelBtn.sd_layout
            .leftSpaceToView(bgView, margin10)
            .topSpaceToView(bgView, 0)
            .widthIs(margin10*6)
            .heightRatioToView(bgView, 1);
            
            self.confirmBtn.sd_layout
            .centerYEqualToView(self.cancelBtn)
            .rightSpaceToView(bgView, margin10)
            .widthRatioToView(self.cancelBtn, 1)
            .heightRatioToView(self.cancelBtn, 1);
            
            self.resignBtn.sd_layout
            .centerXEqualToView(bgView)
            .widthRatioToView(self.confirmBtn, 1)
            .heightRatioToView(self.confirmBtn, 1);
        }
        
        self.tipLabel.sd_layout
        .leftSpaceToView(self, margin10)
        .rightSpaceToView(self, margin10)
        .bottomSpaceToView(self, 0)
        .heightIs(25);
        
        self.signView.sd_layout
        .leftSpaceToView(self, margin10)
        .topSpaceToView(bgView, margin10)
        .rightSpaceToView(self, margin10)
        .bottomSpaceToView(self.tipLabel, 0);
        
    }
    return self;
}

#pragma mark - handle Action

- (void)cancelAction {
    if (_cancelBlock) {
        _cancelBlock();
    }
}

- (void)resignAction {
    if (_resignBlock) {
        _resignBlock();
    }
}

- (void)confirmAction {
    if (_confirmBlock) {
        _confirmBlock();
    }
}




@end
